import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from test import *
from coin_main import *
import requests
import matplotlib.pyplot as plt

class MyWindow(QMainWindow, Ui_MainWindow,Ui_Dialog):
    def __init__(self, parent=None):
        super(MyWindow, self).__init__(parent)
        self.setupUi(self)

    def go_to_coinUI(self):
        self.hide()
        self.coinpage=CoinPage()
        self.coinpage.show()

class CoinPage(QtWidgets.QWidget,Ui_Dialog):
    def __init__(self):
        super(CoinPage, self).__init__()
        self.setupUi(self)

    def Coin_back2Main(self):
        self.hide()
        self.mainpge=MyWindow()
        self.mainpge.show()

    def get_coin_line(self):
        K_line = lambda url, token, sec, hour: requests.get(
            url + token + '?group_sec=' + str(sec) + '&range_hour=' + str(hour)).json()
        result = K_line('https://data.gateio.io/api2/1/candlestick2/', 'btc_usdt', 60, 1)['data']
        high = []
        low = []
        time = []
        # (时间，开盘，收盘，最高，最低)
        for i in result:
            high.append([float(i[3])])
            low.append([float(i[4])])
            time.append([float(i[0])])
        # 出图
        plt.figure(figsize=(20, 20))
        plt.plot(time, high, color='red', label='high')
        plt.plot(time, low, color='green', label='low')
        plt.legend()
        plt.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    myWin = MyWindow()
    myWin.setWindowTitle('常鸿量化机')
    myWin.show()
    sys.exit(app.exec_())
